package com.wlh.animation.property;/*
 * Copyright (C) 2016 Facishare Technology Co., Ltd. All Rights Reserved.
 */

import com.wlh.animation.R;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.AccelerateInterpolator;

/**
 * Created by weilh on 2016/1/22.
 */
public class PropertyAnimationAct extends AppCompatActivity {
    private View translate_btn, scale_btn, alpha_btn, rotation_btn, anim_set_btn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_property_anim);
        setTitle("属性动画");
        translate_btn = findViewById(R.id.translate_btn);
        translate_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator anim = ObjectAnimator.ofFloat(translate_btn, "translationX", 100f, 0f);
                anim.setDuration(3000);
                anim.start();
            }
        });

        scale_btn = findViewById(R.id.scale_btn);
        scale_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator anim = ObjectAnimator.ofFloat(scale_btn, "scaleX", 1f, 2f, 0.5f, 1f);
                anim.setDuration(3000);
                anim.start();
            }
        });

        alpha_btn = findViewById(R.id.alpha_btn);
        alpha_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator anim = ObjectAnimator.ofFloat(alpha_btn, "alpha", 0f, 1f);
                anim.setDuration(3000);
                anim.start();
            }
        });

        rotation_btn = findViewById(R.id.rotation_btn);
        rotation_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator anim = ObjectAnimator.ofFloat(rotation_btn, "rotation", 0f, 360f);
                anim.setDuration(3000);
                anim.start();
            }
        });

        anim_set_btn = findViewById(R.id.anim_set_btn);
        anim_set_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(anim_set_btn, "alpha", 0f, 1f);
                ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(anim_set_btn, "rotation", 0f, 360f);
                alphaAnim.setDuration(3000);
                rotationAnim.setDuration(3000);
                rotationAnim.setInterpolator(new AccelerateInterpolator());
                AnimatorSet anim = new AnimatorSet();
                anim.playTogether(alphaAnim, rotationAnim);
                anim.start();

//                PropertyValuesHolder alphaAnim = PropertyValuesHolder.ofFloat("alpha", 0f, 1f);
//                PropertyValuesHolder rotationAnim = PropertyValuesHolder.ofFloat("rotation", 0f, 370f, 360f);
//                ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(anim_set_btn, alphaAnim, rotationAnim);
//                anim.setDuration(3000);
//                anim.start();
            }
        });
    }
}
